<?php
namespace app\closure\controller;
use app\AdminRest;
use think\App;
use app\closure\model\AdminClosure as Model;
use think\facade\Cache;
use think\facade\Db;

class AdminClosure extends AdminRest
{

    protected $model;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->model= new Model();
    }
    /**
     * User: chenniang
     * Date: 2019-12-18 14:30
     * @return void
     * descrption:配置回显|编辑
     */
    public function closureInfo(){
       $input = $this->_input;

       if(empty($input)||!is_array($input)){

           $this->errorMsg('参数必须是个数组');

       }

       foreach ($input as $value){

           $dis['uniacid'] = $this->_uniacid;

           $dis['key']     = $value;

           $data[] = $this->model->closureInfo($dis);
       }

        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2020-03-06 18:18
     * @功能说明:编辑
     */
    public function closureUpdate(){

        $input = $this->_input;

        if(empty($input)||!is_array($input)){

            $this->errorMsg('参数必须是个数组');

        }
        $icon  = array_column($input,'status');

        $icon  = array_unique($icon);



        if(in_array(1,$icon)&&count($icon)==1){

            $this->errorMsg('只能使用一个');
        }

        foreach ($input as $value){

            $value['token'] = json_encode($value['token']);

            $res = $this->model->closureUpdate(['id'=>$value['id']],$value);
        }

        return $this->success($res);

    }










}
